package com.htg.util;

public class UtilColor {


    /**
     *
     * @param startColor 起始颜色
     * @param endColor 结束颜色
     * @param fraction 一个比例值 取值范围0-1 起始为0 终点为1
     * @return
     */
    public static int interpolateColor(int startColor, int endColor, float fraction) {
        int startA = (startColor >> 24) & 0xff;
        int startR = (startColor >> 16) & 0xff;
        int startG = (startColor >> 8) & 0xff;
        int startB = startColor & 0xff;

        int endA = (endColor >> 24) & 0xff;
        int endR = (endColor >> 16) & 0xff;
        int endG = (endColor >> 8) & 0xff;
        int endB = endColor & 0xff;

        int a = (int) (startA + (endA - startA) * fraction);
        int r = (int) (startR + (endR - startR) * fraction);
        int g = (int) (startG + (endG - startG) * fraction);
        int b = (int) (startB + (endB - startB) * fraction);

        return (a << 24) | (r << 16) | (g << 8) | b;
    }
}
